package model;

import java.util.ArrayList;

public class OOClass extends OOObject {
	private OOPackage parentPackage=null;
	private String filePath=null;
	private OOClass parentClass=null;
	private OOClass associatedClass=null;
	private ArrayList<OOClass> Interfaces=null;
	public ArrayList<OOAttribute> variables=null;
	public ArrayList<OOMethod> methods=null;
	private boolean IsAbstract=false;
	private boolean IsInterface=false;
	public boolean isLinked=false;

	public OOClass() {
		Interfaces = new ArrayList<OOClass>();
		variables = new ArrayList<OOAttribute>();
		methods = new ArrayList<OOMethod>();
	}

	/**
	 * @param parentPackage the parentPackage to set
	 */
	public void setParentPackage(OOPackage parentPackage) {
		this.parentPackage = parentPackage;
	}

	/**
	 * @return the parentPackage
	 */
	public OOPackage getParentPackage() {
		return parentPackage;
	}

	/**
	 * @param filePath the filePath to set
	 */
	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	/**
	 * @return the filePath
	 */
	public String getFilePath() {
		return filePath;
	}

	/**
	 * @param parentClass the parentClass to set
	 */
	public void setParentClass(OOClass parentClass) {
		this.parentClass = parentClass;
	}

	/**
	 * @return the parentClass
	 */
	public OOClass getParentClass() {
		return parentClass;
	}

	/**
	 * @param isAbstract the isAbstract to set
	 */
	public void setIsAbstract(boolean isAbstract) {
		IsAbstract = isAbstract;
	}

	/**
	 * @return the isAbstract
	 */
	public boolean isIsAbstract() {
		return IsAbstract;
	}

	/**
	 * @param isInterface the isInterface to set
	 */
	public void setIsInterface(boolean isInterface) {
		IsInterface = isInterface;
	}

	/**
	 * @return the isInterface
	 */
	public boolean isIsInterface() {
		return IsInterface;
	}

	public void addMethod(OOMethod method) {
		methods.add(method);
	}

	public OOMethod getMethodAt(int index) {
		return methods.get(index);
	}

	public int getMethodsCount() {
		return methods.size();
	}

	public void removeMethodAt(int index) {
		methods.remove(index);
	}

	public void addVariable(OOAttribute variable) {
		variables.add(variable);
	}

	public OOAttribute getVariableAt(int index) {
		return variables.get(index);
	}

	public int getVariablesCount() {
		return variables.size();
	}

	public void removeVariableAt(int index) {
		variables.remove(index);
	}

	public void addInterface(OOClass _interface) {
		Interfaces.add(_interface);
	}

	public OOClass getInterfaceAt(int index) {
		return Interfaces.get(index);
	}

	public int getInterfacesCount() {
		return Interfaces.size();
	}

	public void removeInterfaceAt(int index) {
		Interfaces.remove(index);
	}

	/**
	 * @param associatedClass the associatedClass to set
	 */
	public void setAssociatedClass(OOClass associatedClass) {
		this.associatedClass = associatedClass;
	}

	/**
	 * @return the associatedClass
	 */
	public OOClass getAssociatedClass() {
		return associatedClass;
	}

	public void linkWithClass(OOClass ooClass)
	{
		for(OOAttribute attr:variables)
		{
			if(attr.getType().isLinked==false &&
					attr.getType().getName().equals(ooClass.getName()))
			{
				attr.setType(ooClass);
			}
		}

		for(OOMethod meth:methods)
		{
			if(meth.returnType.isLinked==false &&
					meth.returnType.getName().equals(ooClass.getName()))
			{
				meth.returnType=ooClass;
			}

			OOAttribute methParam;
			for(int i=0;i<meth.getParametersCount();i++)
			{
				methParam = meth.getParameterAt(i);
				if(methParam.getType().isLinked==false)
				{
					if(methParam.getType().getName().equals(ooClass.getName()))
					{
						methParam.setType(ooClass);
					}
				}
			}
		}

		if(parentClass!=null &&
				parentClass.isLinked ==false &&
				parentClass.getName().equals(ooClass.getName()))
		{
			parentClass=ooClass;
		}
	}


	public void linkWithPackage(OOPackage pkg)
	{
		if(pkg.name.equals(parentPackage.name))
		{
			parentPackage = pkg;
		}
	}
}
